package com.liufei.starter.config;

import com.liufei.starter.properties.LocationProperties;
import com.liufei.starter.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(LocationProperties.class)
@ConditionalOnClass(LocationService.class)
@ConditionalOnProperty(prefix = "location",name = "enable",matchIfMissing = true)
public class LocationConfig {
    @Autowired
    private LocationProperties properties;

    @Bean(name = "location")
    @ConditionalOnMissingBean(LocationService.class)
    public LocationService locationService(){
        return new LocationService(properties.getCity(),properties.getArea());
    }
}
    